package com.cl.ks.schedule;

import com.cl.ks.service.AutoFilterService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

/**
 * 增量处理任务
 *
 * @author chenyitao
 * @date 2021/7/5
 */
@Configuration
@EnableScheduling
@EnableAsync(proxyTargetClass = true)
public class AutoFilterSchedule implements SchedulingConfigurer {

    private final AutoFilterService autoFilterService;

    public AutoFilterSchedule(AutoFilterService autoFilterService) {
        this.autoFilterService = autoFilterService;
    }

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(this::schedule,
                triggerContext -> new CronTrigger("0 0 4 * * ?")
                        .nextExecutionTime(triggerContext));
    }

    public void schedule(){
        autoFilterService.autoUpdate();
    }


}
